<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%
    String base = request.getContextPath();
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=base %>/view/FCKeditor/fckeditor.js"></script> <!--载入fckeditor类-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript" src="../view/admin/js/jquery-1.7.2.min.js"></script>
<title>添加文章</title>
</head>
<script>
	function addArticle(){
		var article_title = document.getElementById("article_title").value;
		var classifyId = document.getElementById("classifyId").value;
		var articleId = document.getElementById("articleId").value;
		if(""==article_title || article_title==null){
			alert("标题为空！");
			return;
		}
		var oEditor = FCKeditorAPI.GetInstance("FCKeditor1");
	    var content = oEditor.EditorDocument.body.innerHTML;//这样可以获得内容，并且带有样式标签
	    content = encodeURIComponent(content);
	    var pathName=window.document.location.pathname;
		var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
			$.ajax({
				type : 'POST',
				url : projectName+"/article/add",
				data : { 'article_title':article_title,'article_content':content,'classifyId':classifyId,"articleId":articleId},
				async : false,
				success : function(data,status){ 
			        if(status == "success"){  
			        	if(data=="add"){
			        		alert("成功添加！");
			        		document.getElementById("article_title").value="";
			        		oEditor.EditorDocument.body.innerHTML="";
			        	}
			        	if(data=="update"){
			        		alert("成功更新！");
			        	}
			        }  
				}
			});
	}
</script>
<body>
<%
	Object tempTitile = request.getSession().getAttribute("articleTitle");
	Object tempId = request.getSession().getAttribute("articleId");
	Object tempCId = request.getSession().getAttribute("classifyId");
	Object tempContent = request.getSession().getAttribute("articleContent");
	String articleTitle = "";
	String articleId = "";
	String classifyId = "";
	String articleContent = "";
	if(tempTitile==null){
		articleTitle="";
	}else{
		articleTitle=tempTitile.toString();
	}
	
	if(tempId==null){
		articleId="";
	}else{
		articleId=tempId.toString();
	}
	
	if(tempCId==null){
		classifyId="";
	}else{
		classifyId=tempCId.toString();
	}
	
	if(tempContent==null){
		articleContent="";
	}else{
		articleContent=tempContent.toString();
	}
	out.print("<input type='hidden' id='classifyId' value=\""+classifyId+"\">");
	out.print("<input type='hidden' id='articleId' value=\""+articleId+"\">");
%>
标题： <input id="article_title" value="<%=articleTitle%>"><br>
<script type="text/javascript">
  var oFCKeditor = new FCKeditor('FCKeditor1');
  oFCKeditor.BasePath = "./";
  oFCKeditor.Height="530";
  var content = "<%=articleContent%>";
  if(content != null){
	 content = decodeURIComponent(content);
 	 oFCKeditor.Value=content;
  }
  oFCKeditor.Create();
</script>
<input type="button" onclick="addArticle()" value="提交">
</form>
</body>

</body>
</html>